/**
 *
 * @author 
 *
 */
class Page2 extends egret.Sprite {
    private _main: Main;
    public constructor(main: Main) {
        super();
        this._main = main;
        
        
        //this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.thisClick, this)
        
    }
    
    private touchMove(e: egret.TouchEvent): void
    {
        this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.thisClickMove,this);
    }
    
    private mClickNum: number = 0;
    private mSkin: Boolean;
    private m_move_y = 0;
    private mChangeing: boolean;
    
    
    private thisClickMove(e: egret.TouchEvent): void
    {
        if(this.mChangeing) return;
        if(this.m_move_y == 0)
            this.m_move_y = e.stageY;
        else
            if(this.m_move_y > e.stageY) 
            {
                this.mChangeing = true;
                this._main.toPage3(this, true);
                egret.setTimeout(clean, this, 500);

            }
            else if(this.m_move_y == e.stageY)
            {}
            else
            {
                this.mChangeing = true;
                this._main.toPage1(this, false);   
                egret.setTimeout(clean, this, 500);
            }
            
        function clean(): void
        {
            this.mChangeing = false;
        }
    }
    
    private thisClick(e: egret.TouchEvent): void
    {
        this.mClickNum++;
        if(this.mClickNum == 1)
        {
            this.mSkin = true;
            return;
        }

        if(this.mClickNum >= 2)
        {
            this._main.toPage3(this, true);
            return;
        }
    }
    
    public start(): void {
        egret.setTimeout(this.touchMove,this,this.mSkin ? 0 : 500);
        
        var bg: eui.Image = new eui.Image;
        bg.source = "1_1_png";
        this.addChild(bg);
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_arrows_png";
        bg2.x = 300;
        bg2.y = 960;
        this.addChild(bg2);
        
        egret.setTimeout(this.page1, this, this.mSkin ? 0 : 100);
    }
    
    public page1(): void {
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_2_1_png";
        bg2.x = -370;
        bg2.y = 75;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            x: 0, alpha:1, ease: egret.Ease.bounceInOut
        },500)
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_2_2_png";
        bg2.x = 80;
        bg2.y = 800;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            y: 200,alpha: 1, ease: egret.Ease.bounceInOut
        },this.mSkin ? 0 : 500)
        
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_2_4_png";
        bg2.x = 500;
        bg2.y = 400;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            x: 350,alpha: 1, ease: egret.Ease.bounceInOut
        },this.mSkin ? 0 : 300)

        
        
        
        egret.setTimeout(this.page2, this, this.mSkin ? 0 : 200);
    }
    
    public page2(): void {
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_2_3_png";
        bg2.x = 80;
        bg2.y = 980;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            y: 380,alpha: 1,ease: egret.Ease.bounceInOut
        },this.mSkin ? 0 : 500)

        egret.setTimeout(this.page3,this,this.mSkin ? 0 : 0);
    }
    
    public page3(): void {
        var bg2: eui.Image = new eui.Image;
        bg2.source = "n_2_5_png";
        bg2.x = 50;
        bg2.y = 900;
        bg2.alpha = 0;
        this.addChild(bg2);

        egret.Tween.get(bg2).to({
            y: 800,alpha: 1,ease: egret.Ease.bounceInOut
        },this.mSkin ? 0 : 500)
        
        this.mClickNum = 1;
    }
}
